<?php
require('../../../wp-config.php');
$plugin_url = trailingslashit( WP_PLUGIN_URL.'/'. dirname( plugin_basename(__FILE__)));
global $wpdb;
$data['date'] = date('Y-m-d h:m:s');
$data['name'] = $_POST['name'];
$data['code'] = $_POST['code'];
$data['description'] = $_POST['description'];
$data['bed_room'] = $_POST['bed_room'];
$data['type'] = $_POST['type'];
$data['location'] = $_POST['location'];
$data['price'] = $_POST['price'];
$data['address'] = $_POST['address'];
$wpdb->insert('wp_house',$data);
$id = $wpdb->get_var("SELECT MAX(id) FROM wp_house");
foreach($wpdb->get_results("SELECT * FROM wp_category") as $row)
{
    $att = 'attribute'.$row->id;
    if(count($_POST[$att]) > 0){
    foreach($_POST[$att] as $key=>$value){
        $wpdb->insert('wp_value',array('id_att'=>$key,'id_house'=>$id));
    }
    }
}
if($_POST['image'] != ''){
foreach(explode(',',$_POST['image']) as $row){
    $wpdb->insert('wp_image',array('id_house'=>$id,'link'=>$row));
}
    $wpdb->update('wp_image',array('main'=>1),array('link'=>$_POST['main_image']));
}
?>
<script>window.location = '<?php echo get_bloginfo('url'); ?>/wp-admin/admin.php?page=steel.php';</script>